home *** CD-ROM | disk | FTP | other *** search
- Path: troll.powertech.no!news
- From: Geir Thomassen <geirt@powertech.no>
- Newsgroups: comp.lang.c
- Subject: Recursion in C pre-processor ?
- Date: Tue, 16 Jan 1996 13:06:21 -0800
- Organization: Jotron Electronics
- Message-ID: <30FC134D.3A8F@powertech.no>
- NNTP-Posting-Host: port-220.ppp.powertech.no
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b3 (Win16; I)
-
- Hello World !!\n
-
- I have a function declared as
-
- void func(void);
-
- In a typical application, the call to func() is repeated many times in
- a row:
-
- func(); func(); func(); ..... ; func();
-
- To make my code more readable I would like a macro DoFunc(n) which expands
- to n calls to func(). I tried to make a recursive macro, but it did not
- pass cpp.
-
- #define DoFunc(n)\ /* Don't work !! */
- #if n\
- func();\
- DoFunc(n-1);\
- #endif
-
-
- Why ?? Does cpp stop expanding the #if n ... #endif in the first pass
- if n=0, or does it expand forever ??
-
- Does anyone have a better (working) idea ?? The idea of recursion is
- probably a wrong track! Please help !!
-
- Why do I want to do this ?? The function func() emits a NOP assembly
- instruction into the instruction stream. The code is for a slow 8051
- micro controller with 1 us instruction cycle, and the NOPs are used
- for timing. DoFunc(5) would give me 5 us delay, in just 5 bytes of code !!
-
- --
- | Geir Thomassen, | geirt@powertech.no |
- | R&D Engineer, electronics (MSc) | LA7HFA, qrv 2.45GHz :-) |
- | | |
- | Jotron Electronics a.s. | Phone +47 33124577 |
- | P.O. Box 85 | Fax +47 33126780 |
- | N-3280 Tjodalyng | Priv +47 33458231 |
- | Norway | Telex 21715 TRON N |
- | |
- | 9.81 m/s^2 - the best way to accelerate a PC ! |
-
-
- PS: Sorry if this is a repost, I don't think it made it the
- first time ...
-